package com.wanho.java157.crm.personalOffice.task.controller;

import com.github.pagehelper.PageInfo;
import com.wanho.java157.crm.personalOffice.task.po.IndividualTask;
import com.wanho.java157.crm.personalOffice.task.service.IndividualTaskService;
import com.wanho.java157.crm.systemSettings.manage.po.Employee;
import com.wanho.java157.crm.systemSettings.manage.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.List;

@Controller
@RequestMapping("/task")
@Slf4j
public class IndividualTaskController {
    @Autowired
    private IndividualTaskService individualTaskService ;
    @Autowired
    private EmployeeService employeeService ;


    @RequestMapping("/list")
    public String list(@RequestParam(value = "page",defaultValue = "1",required = false) int page,
                       @RequestParam(value = "size",defaultValue = "1",required = false) int size,
                       @RequestParam(value = "employeeId",defaultValue = "4",required = false) int employeeId,
                       Model model){
        PageInfo<IndividualTask> pageInfo = individualTaskService.listPage(page, size, employeeId);
        model.addAttribute("pageInfo",pageInfo) ;
        return "personalOffice/task/index" ;
    }

    @RequestMapping("/toAddView")
    public String toAddView(Model model){
        List<Employee> employeeList = employeeService.selectEmployeeAndDepartmentAndPosition();
        model.addAttribute("employeeList",employeeList) ;
        return "personalOffice/task/create" ;
    }

    @RequestMapping("/add")
    public String add(IndividualTask task){
        System.out.println("============");
        log.debug(task.toString());
        individualTaskService.addTask(task) ;
        return "redirect:/task/list" ;
    }
}
